package com.jzit168.library_utils

import android.content.Context
import com.tencent.mmkv.MMKV

/**
 *@Desc:
 *@Author: Android Developer
 *@Date: 2020/10/15
 *
 **/
object MMKVUtil {


    //初始化MMKV
    fun init(context: Context) {
        MMKV.initialize(context)
    }

    fun setString(key: String, value: String) {
        MMKV.defaultMMKV().encode(key, value)
    }

    fun setBoolean(key: String, value: Boolean) {
        MMKV.defaultMMKV().encode(key, value)
    }

    fun setInt(key: String, value: Int) {
        MMKV.defaultMMKV().encode(key, value)
    }

    fun setLong(key: String, value: Long) {
        MMKV.defaultMMKV().encode(key, value)
    }

    fun getString(key: String): String = MMKV.defaultMMKV().decodeString(key, "")

    fun getBoolean(key: String): Boolean = MMKV.defaultMMKV().decodeBool(key, false)

    fun getInt(key: String): Int = MMKV.defaultMMKV().decodeInt(key, 0)

    fun getLong(key: String): Long = MMKV.defaultMMKV().decodeLong(key, 0L)

    fun removed(key: String) {
        MMKV.defaultMMKV().removeValueForKey(key)
    }
}